package com.develop.skwen.yourelectricmall.util;

import android.app.Activity;
import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.develop.skwen.yourelectricmall.R;

/**
 * Created by skwen
 * on 18-4-24
 */

public class TitleBarUtil {




    private static TitleBarUtil mInstance;


    private TitleBarUtil(){

    }

    public static TitleBarUtil getInstance(){
        if (mInstance == null){
            synchronized (TitleBarUtil.class){
                if (mInstance == null){
                    mInstance = new TitleBarUtil();
                }
            }
        }
        return mInstance;
    }



    public void setTitleBarTheme(int position,Activity activity){
        Window window = activity.getWindow();
        //设置状态栏颜色
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //取消设置透明状态栏,使 ContentView 内容不再覆盖状态栏
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

            //需要设置这个 flag 才能调用 setStatusBarColor 来设置状态栏颜色
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            int ids;
            switch (position){
                case 0:
                    ids = R.color.home_color_title;
                    break;
                case 1:
                    ids = R.color.category_color_title;
                    break;
                case 2:
                    ids = R.color.shop_color_title;
                    break;
                case 3:
                    ids = R.color.mine_color_title;
                    break;
                default:
                    ids = 0;
                    break;
            }
            window.setStatusBarColor(ids);
            ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);
            View mChildView = mContentView.getChildAt(0);
            if (mChildView != null) {
                //注意不是设置 ContentView 的 FitsSystemWindows, 而是设置 ContentView 的第一个子 View . 预留出系统 View 的空间.
                ViewCompat.setFitsSystemWindows(mChildView, true);
            }
        }


    }


}
